package kzhang.dbtest.derby.basic;

import java.sql.*;

public class UsersTest {
    public static void main(String[] args) {
        init();

    }

    public static void init() {
        String driver = "org.apache.derby.jdbc.EmbeddedDriver";
        String dbName = "../db/firstdb";
        String connURL = "jdbc:derby:" + dbName + ";";
        
        try {
            Class.forName(driver);
            Connection conn = DriverManager.getConnection(connURL);
            Statement s = conn.createStatement();
            ResultSet result = s.executeQuery("select * from users");
            
            while (result.next()) {
                log(result.getString(2));
                log(result.getString(3));
            }
            
            if (s != null) s.close();
            if (conn != null) conn.close();
            DriverManager.getConnection("jdbc:derby:;shutdown=true");
            
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
    }
    
    private static void log(Object obj) {
        System.out.println(obj.toString());
    
    }
}
